package weaver.interfaces.cese.duss.action.srm;

import com.engine.cese.duss.srm.util.GenUtil;
import com.weaver.general.BaseBean;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 公告发布流程
 * @ModifyLog:
 **/
/*
 *@Description: 根据竞价立项流程requestid插入流程数据竞价信息表
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaAddBidInfoAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        try {
            String sql = "select cglxd,gysmc from " + tablename + " where requestid=? and xzbm=0";
            rs.executeQuery( sql, requestid );
            rs.next();
            String cglxd = Util.null2String( rs.getString( "cglxd" ) );//采购立项单
            String gysid = Util.null2String( rs.getString( "gysmc" ) );//供应商Id
            Map<String,String>  strMap = getCrmLoginId2Name( gysid );//供应商名称
            String lastname = strMap.get("lastname");
            String loginid = strMap.get("loginid");
            String jmgysmc = "******";//加密供应商名称
            String dh = GenUtil.genrateStr( 4 );
            String jmdh = "******";
            String bjcs = "0";
            String zxbj = "0";
            String zdcscs = "0";
            String sycs = "0";
            String jmzxbj = "******";
            String rqsj = DateUtil.getFullDate();//日期时间
            String sql2 = "insert into uf_bidguestinfo(cglxd,gysid,gysmc,jmgysmc,dh,jmdh,zxbj,jmzxbj,bjcs,zdcscs,sycs,rqsj) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = {cglxd, loginid, lastname, jmgysmc, dh, jmdh, zxbj, jmzxbj, bjcs, zdcscs, sycs, rqsj};
            rs.executeUpdate( sql2, params );
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

    //根据loginID获取客户模块loginid名称
    public static Map<String,String> getCrmLoginId2Name(String id){
        RecordSet rs = new RecordSet();
        Map<String,String> dataMap = new HashMap<>(  );
        String sql = "select name,portalloginid from crm_customerinfo where id=?";
        rs.executeQuery( sql, id );
        rs.next();
        String lastname = weaver.general.Util.null2String( rs.getString( "name" ) );
        String loginid = weaver.general.Util.null2String( rs.getString( "portalloginid" ) );
        dataMap.put( "lastname",lastname);
        dataMap.put( "loginid",loginid);
        return dataMap;
    }
}
